package nxu.it.util;

import java.util.regex.Pattern;

public class FormatCheckerUtil {
	//信息验证工具类
	
	private static String defaultFormat = "";
	//字母开头，允许4-15字节，允许字母数字下划线
	private static String accountFormat = 
			"^[a-zA-Z][a-zA-Z0-9_]{4,15}$";
	//必须包含大小写字母和数字的组合，不能使用特殊字符，长度在6-16之间
	private static String passwordFormat = 
			"^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{6,16}$";
	//Email地址
	private static String emailFormat = 
			"^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
	//电话号码
	private static String phoneFormat = 
			"^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$";
	//这里暂时没必要用，为了各位的安全
	private static String idcardFormat = 
			"^(\\d{15}|\\d18|^\\d{17}(\\d|X|x))$";
	
	//取消警告
	@SuppressWarnings("unused")
	private static Pattern pattern = Pattern.compile(defaultFormat);
	
	
	
	//账号格式检验
	static public boolean checkAccount(String account) {
		return Pattern.matches(accountFormat, account);
	}
	//密码格式检验
	static public boolean checkPassword(String password) {
		return Pattern.matches(passwordFormat, password);
	}
	//电子邮件格式检验
	static public boolean checkEmail(String email) {
		return Pattern.matches(emailFormat, email);
	}
	//电话号码格式检验
	static public boolean checkPhone(String phone) {
		return Pattern.matches(phoneFormat, phone);
	}
	//身份证格式检验
	static public boolean checkIdcard(String idcard) {
		return Pattern.matches(idcardFormat, idcard);
		
	}
}
